package com.shizhanzhe.zxbapp.vip;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.gyf.barlibrary.ImmersionBar;
import com.shizhanzhe.zxbapp.R;
import com.shizhanzhe.zxbapp.bean.UserBean;
import com.shizhanzhe.zxbapp.url.Path;
import com.shizhanzhe.zxbapp.utils.OkHttpDownloadJsonUtil;
import com.shizhanzhe.zxbapp.widget.SignDialog;

import org.json.JSONException;
import org.json.JSONObject;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

/**
 * Created by zz9527 on 2018/12/21.
 */
public class ZhuanPan extends Activity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhuanpan);
        ImmersionBar.with(this).statusBarColor(R.color.them).fitsSystemWindows(true).init();
        findViewById(R.id.backarea).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        final SignDialog dialog = new SignDialog(this);
        OkHttpDownloadJsonUtil.downloadJson(this, Path.ZHUANPAN(UserBean.uid), new OkHttpDownloadJsonUtil.onOkHttpDownloadListener() {
            @Override
            public void onsendJson(String json) {
                try {
                    JSONObject object = new JSONObject(json);
                    final String data = object.optString("data");
                    findViewById(R.id.wx).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if ("".equals(data)) {
                                dialog.setListener(new SignDialog.SignListener() {
                                    @Override
                                    public void checktrue() {
                                        dialog.dismiss();
                                    }
                                });
                                dialog.show();
                                dialog.showMsg("请联系客服开通购物赚抽免单功能");
                            } else {
                                final String url = data.split(",")[0];
                                Wechat.ShareParams sp = new Wechat.ShareParams();
                                sp.setTitle("购物赚抽免单！");
                                sp.setText("赚小宝平台，一个用手机赚钱的App");
                                sp.setUrl(url);
                                sp.setImageUrl("http://zhuanxiaobao.com/static/index/logo2.png");
                                sp.setShareType(Platform.SHARE_WEBPAGE);
                                Platform weChat = ShareSDK.getPlatform(Wechat.NAME);
                                weChat.share(sp);
                            }
                        }
                    });
                    findViewById(R.id.pyq).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if ("".equals(data)) {
                                dialog.setListener(new SignDialog.SignListener() {
                                    @Override
                                    public void checktrue() {
                                        dialog.dismiss();
                                    }
                                });
                                dialog.show();
                                dialog.showMsg("请联系客服开通购物赚抽免单功能");
                            } else {
                                final String url = data.split(",")[0];
                                WechatMoments.ShareParams sp = new WechatMoments.ShareParams();
                                sp.setTitle("购物赚抽免单！");
                                sp.setText("赚小宝平台，一个用手机赚钱的App");
                                sp.setUrl(url);
                                sp.setImageUrl("http://zhuanxiaobao.com/static/index/logo2.png");
                                sp.setShareType(Platform.SHARE_WEBPAGE);
                                Platform weChatMoments = ShareSDK.getPlatform(WechatMoments.NAME);
                                weChatMoments.share(sp);
                            }
                        }
                    });

                } catch (
                        JSONException e)

                {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ImmersionBar.with(this).destroy();
    }
}
